<?php
/**
 * Eren Framework
 * 
 * Request URL Operate
 * 
 * @category System
 * @author Manu Soros Leu
 * @copyright manusoros@gmail.com
 */

class Eren_Request_URL
{
    
    /**
     * Get The Request Host
     * 
     * @return string   For example:www.eshifang.com
     */
    public static function getHost() 
    {
        return $_SERVER['HTTP_HOST'];
    }
    
    /**
     * Get Request URL
     * 
     * @return string   For example:http://www.eshifang.com/aa/bb/cc/dd
     */
    public static function getURL()
    {
        return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    }
    
    /**
     * Get Referer URL
     * 
     * @return string   For example:http://www.eshifang.com/aa/bb/cc/dd
     */
    public static function getRef()
    {
        return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
    }
    
    /**
     * Get Client IP Address
     * 
     * @return string   For example:192.168.1.1
     */
    public static function getIP()
    {
         return isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $_SERVER['REMOTE_ADDR'];
    }
    
    /**
     * Get The Request QueryString
     *
     * @return string   For example:/aa/bb/cc/dd?a=b&b=c
     */
    public static function getQueryString()
    {
        return isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ""; 
    }
    
    /*
     * Get The Request RouterString
     *
     * @return string   For example:/aa/bb/cc/dd
     */
    public static function getRouterString()
    {
        $queryString = self::getQueryString();
        $router = strstr($queryString, '?', true);
        if($router != false){
            $queryString = $router;
        }
        
        return $queryString;
    }
    
    /**
     * To test if Reuqest if the GET Method
     * 
     * @return bool
     */
    public static function isGet()
    {
        if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET'){
            return TRUE;
        }
        return FALSE;
    }
    
    /**
     * To test if Reuqest if the POST Method
     * 
     * @return bool
     */
    public static function isPost()
    {
        if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST'){
            return TRUE;
        }
        return FALSE;
    }
}